package com.example.final_project.Cate.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.final_project.Cate.entry.CateCars;
import com.example.final_project.R;

import java.util.List;

public class CateCarAdapter extends RecyclerView.Adapter {

    private Context context;
    private List<CateCars> list;

    public CateCarAdapter(Context context, List<CateCars> list){
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.cate_cars_kid,parent,false);
        CateCatHolder cateCatHolder = new CateCatHolder(view);
        return cateCatHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        CateCatHolder cateCatHolder = (CateCatHolder)holder;
        cateCatHolder.setData(position);
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class CateCatHolder extends RecyclerView.ViewHolder {
        public CateCatHolder(@NonNull View itemView) {
            super(itemView);
        }

        public void setData(int position){
            CateCars cateCars = list.get(position);
            ImageView imageView = itemView.findViewById(R.id.Ccar_img);
            Glide.with(context).load("http://10.150.11.9:8086/chengcar/banners/"+cateCars.getImg1()).into(imageView);
            TextView textView = itemView.findViewById(R.id.Ccar_name);
            textView.setText(cateCars.getCarname());
            TextView textView1 = itemView.findViewById(R.id.Ccar_price);
            textView1.setText(cateCars.getPrice());
        }

    }

}
